package com.mdb.open.trade.resource.trade;

/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfLoanRemittanceService.java
* Author:   you.yichao
* Date:     2019-07-02
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-07-02          V1.00        代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.enums.OrderByEnum;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.trade.constant.trade.Fields;
import com.mdb.open.trade.domain.bo.trade.QueryLoanRemitPageListBo;
import com.mdb.open.trade.domain.dto.trade.QueryLoanRemitPageListDto;
import com.mdb.open.trade.domain.po.trade.LoanRemittance;
import com.mdb.open.trade.domain.vo.trade.LoanRemittancePageListVo;
import com.mdb.open.trade.service.trade.TfLoanRemittanceService;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类描述：
 *  放款表 前端控制器
 *
 * @author you.yichao
 * @date 2019-07-02
 */
@RestController
@RequestMapping("tf/loan")
@Api(tags = "贸易金融放款")
public class LoanRemittanceResource extends SuperResources {

    @Autowired
    TfLoanRemittanceService tfLoanRemittanceService;

    @Autowired
    LoginUserInfoHelper loginUserInfoHelper;

    @LogAnnotation
    @ApiOperation("放款表列表 - 分页查询")
    @GetMapping("/page_list")
    public ListResultEx<LoanRemittancePageListVo> findByConditionPage(@ModelAttribute QueryLoanRemitPageListDto dto) {

        QueryLoanRemitPageListBo bo = new QueryLoanRemitPageListBo();
        bo.setStartDate(dto.getStartDate());
        bo.setEndDate(dto.getEndDate());
        bo.setBusinessNo(dto.getBusinessNo());
        bo.setApplyOrderNo(dto.getApplyOrderNo());
        bo.setReceiveAcc(dto.getReceiveAcc());
        bo.setFileStatus(dto.getFileStatus());
        bo.setPageNo(dto.getPageNo());
        bo.setPageSize(dto.getPageSize());
        bo.setOrder(dto.getOrder());
        bo.setSort(dto.getSort());
        bo.setCustomerCode(loginUserInfoHelper.getCustomerCode(true));
        if (ObjectUtil.isEmpty(dto.getSort())) {
            bo.setSort(Fields.ID);
            bo.setOrder(OrderByEnum.DESC);
        }
        //分页查询
        IPage<LoanRemittance> page = tfLoanRemittanceService.pageQuery(bo);

        List<LoanRemittancePageListVo> resultList = Lists.newArrayList();
        for (LoanRemittance remittance : page.getRecords()) {
            LoanRemittancePageListVo vo = new LoanRemittancePageListVo();
            vo.setCustomerCode(remittance.getCustomerCode());
            vo.setCustomerName(remittance.getCustomerName());
            vo.setMerchantNo(remittance.getMerchantNo());
            vo.setMerchantName(remittance.getMerchantName());
            vo.setLoanContractNo(remittance.getLoanContractNo());
            vo.setApplyOrderNo(remittance.getApplyOrderNo());
            vo.setLoanNo(remittance.getLoanNo());
            vo.setBusinessNo(remittance.getBusinessNo());
            vo.setReceiveAcc(remittance.getReceiveAcc());
            vo.setReceiveBank(remittance.getReceiveBank());
            vo.setOutwardDate(remittance.getOutwardDate());
            vo.setPayDate(remittance.getPayDate());
            vo.setPrincipal(remittance.getPrincipal());
            vo.setCcy(remittance.getCcy());
            vo.setTotalRate(remittance.getTotalRate());
            vo.setOverdueRate(remittance.getOverdueRate());
            vo.setValueDate(remittance.getValueDate());
            vo.setExpiryDate(remittance.getExpiryDate());
            vo.setStatus(remittance.getStatus());
            vo.setRemark(remittance.getRemark());
            vo.setCreateTime(remittance.getCreateTime());
            vo.setUpdateTime(remittance.getUpdateTime());
            resultList.add(vo);
        }

        return ListResultEx.ok(resultList, page.getTotal(), page.getCurrent(), page.getSize());

    }

}
